home *** CD-ROM | disk | FTP | other *** search
- // 1/6/00 VERSION 2
- <SCRIPT LANGUAGE="JavaScript" defer>
-
- function ShowZapper(strSelection, strContext, index)
- {
- var Zapper = new ActiveXObject("Zapper.GLZapper");
- Zapper.Text = strSelection;
- Zapper.Context = strContext;
- Zapper.Index = index;
- Zapper.OpenZapper();
- }
-
- function FindTextAndShowZapper()
- {
- var parentwin = external.menuArguments;
- var doc = parentwin.document;
-
- //declare empty variable
- strSelection = new String("");
- strContext = new String("");
- var index = -1;
-
- var sel = doc.selection;
- if (sel == 0)
- {
- ShowZapper(strSelection, strContext, index);
- return;
- }
- var rng = sel.createRange();
- if (rng == 0)
- {
- ShowZapper(strSelection, strContext, index);
- return;
- }
-
- // Get the text from the selection:
- strSelection = new String(rng.text);
-
- var element = rng.parentElement();
-
- // if the tag's name is IMG - no need to present it, just get out
- if ( (element != 0) && (element.tagName != "IMG"))
- {
- //if it's a font kind tag (bold, italic...), go up to the FONT parent's parent,
- //and continue from there:
- elementTagName = new String(element.tagName);
- if ((elementTagName == "I") || (elementTagName == "B") ||
- (elementTagName == "U") || (elementTagName == "S"))
- {
- do
- {
- if (element.parentElement != 0)
- element = element.parentElement;
- elementTagName = element.tagName;
- }
- while(elementTagName == "FONT");
-
- var tempElement = element.parentElement;
- //don't go to the object's parent if it's a link
- if (tempElement.tagName != "A")
- element = tempElement;
- }
-
- var context = doc.body.createTextRange();
- context.moveToElementText(element);
-
- strContext = new String(context.text);
-
- //if Context is empty and Selection is not empty, so try and get the Context out of the IEAutomator
- if ( strContext.empty && !strSelection.empty)
- {
- ShowZapper(strSelection, strContext, index);
- return;
- }
-
- // Compute index as the length of the part of the context before
- // the beginning of the selection
- context.setEndPoint("EndToStart", rng);
- index = context.text.length;
-
- // Get previous and next siblings of pElement, by iterating on pElement's
- // parent's children collection.
- // Unfortunately, the prevSibling and nextSibling methods were introduced only
- // in IE5.
- var parentToElement = element.parentElement;
- if ( parentToElement != 0 )
- {
- //make sure parentToElement has children container
- while(parentToElement.tagName == "FONT")
- {
- if (parentToElement.parentElement != 0)
- parentToElement = parentToElement.parentElement;
- else
- break;
- }
- var siblings = parentToElement.children;
- var prevElement = 0;
- var nextElement = 0;
- var i = 0;
- for (i = 0; i < siblings.length; i++)
- {
- var p = siblings.item(i);
- if (p == element)
- {
- break;
-
- }
- prevElement = p;
- }
- if (i < siblings.length - 1)
- nextElement = siblings.item(i + 1);
- if (i >= siblings.length)
- {
- // What??? pElement is not a child of its own parent???
- // This shouldn't happen!
- prevElement = nextElement = 0;
- }
-
- // add previous element to context:
- if (prevElement)
- {
- strPrevText = new String();
- // if it has kids, take the text from the last child:
- var children = prevElement.children;
- if (children != 0 && children.length)
- {
- var prevChild = children.item(children.length - 1);
- if (prevChild != 0)
- {
- //if tag is a script tag (contain '!' in the tagName) than there is no innerText
- //same for BASE tag
- index = (prevChild.tagName).indexOf("!",0);
- if ( (index != 0) && (prevChild.tagName != "BASE") )
- strPrevText = prevChild.innerText;
- }
- }
- // if it doesn't have kids, take the whole element's text
- if (strPrevText.empty)
- strPrevText = prevElement.innerText;
-
- spaceStr = new String(" ");
- strContext = strPrevText + spaceStr + strContext;
- index += strPrevText.length + 1;
- }
-
- // add next element to context:
- if (nextElement)
- {
- strNextText = new String();
- //if it has kids, take the text from the first child:
- var children = nextElement.children;
- if (children != 0 && children.length)
- {
- var nextChild = children.item(0);
- if (nextChild != 0)
- {
- //if tag is a script tag (contain '!' in the tagName) than there is no innerText
- //same for BASE tag
- index = (nextChild.tagName).indexOf("!",0);
- if ( (index != 0) && (nextChild.tagName != "BASE") )
- strNextText = nextChild.innerText;
- }
- }
- //if it doesn't have kids, take the whole element's text
- if (strNextText.empty)
- strNextText = nextElement.innerText;
-
- var spaceStr = new String(" ");
- strContext = strContext + spaceStr + strNextText;
- }
- }
- }
-
- ShowZapper(strSelection, strContext, index);
- }
-
- FindTextAndShowZapper();
-
- </SCRIPT>
-
-
-
-
-